﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Control
{
    internal class SInterface4 : ISInterface
    {
        #region ISInterface

        public void SendTelegram(Telegram telegram, Target target)
        {
            // first check the received telegramObject, is it supported by interface S4?
			VerifyTelegram(telegram);

            // second check the received Target object, is it supported by interface S4
            if (target is TargetSerial)
            {
                // ok everything is fine
            }

            // for the given target get the corresponding transport object from the transport layer...
        }

        #endregion ISInterface

        #region private helpers

		private static void VerifyTelegram(Telegram telegram)
		{
			// user data 52H and 53H are not allowed at S4 -> check if we have telegrams containing user data
			UserDataColl userDataColl;
			bool userDataFound = TelegramHelper.GetUserDataColl(telegram, out userDataColl);
			if (userDataFound)
			{
				// check if 52H or 53H are included
				if (userDataColl != null)
				{
					foreach (UserData userData in userDataColl)
					{
						if (userData.DataType == UserData.UserData52CommunicationAddressS2)							
						{
							// TODO agree on error handling and change this
							throw new ArgumentException("Telegram 53H not supported for S4");
						}

						if (userData.DataType == UserData.UserData53CommunicationAddressS3)
						{
							// TODO agree on error handling and change this
							throw new ArgumentException("Telegram 53H not supported for S4");
						}
					}
				}
			}
		}

        #endregion private helpers
    }
}
